package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertRuleDto;
import com.zzyl.service.AlertRuleService;
import com.zzyl.vo.AlertRuleVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @version 1.0
 * @Author 小王要变胖
 * @Date 2025/2/16 10:50
 * @注释
 */
@RestController
@RequestMapping("/alert-rule")
public class AlertRuleController extends BaseController{
    @Autowired
    private AlertRuleService alertRuleService;

    @PostMapping("/create")
    @ApiOperation(value = "新增规则")
    public ResponseResult create(@RequestBody AlertRuleDto alertRuleDto) {
        alertRuleService.create(alertRuleDto);
        return success();
    }

    @GetMapping("/get-page")
    @ApiOperation(value = "分页查询规则")
    public ResponseResult<PageResponse<AlertRuleVo>> getPage(Integer pageNum,Integer pageSize,String alertRuleName,String functionName,String productKey) {
        PageResponse<AlertRuleVo> list = alertRuleService.getPage(pageNum,pageSize,alertRuleName,functionName,productKey);
        return success(list);
    }


    @GetMapping("/read/{id}")
    @ApiOperation(value = "查询单个规则")
    public ResponseResult<AlertRuleVo> getById(@PathVariable Long id) {
        AlertRuleVo alertRuleVo = alertRuleService.getById(id);
        return success(alertRuleVo);
    }

    @PutMapping("update/{id}")
    @ApiOperation(value = "更新规则")
    public ResponseResult updateById(@PathVariable Long id,@RequestBody AlertRuleDto alertRuleDto) {
        alertRuleService.updateById(id,alertRuleDto);
        return success();
    }

    @DeleteMapping("delete/{id}")
    @ApiOperation(value = "删除告警规则")
    public ResponseResult deleteById(@PathVariable Long id) {
        alertRuleService.deleteById(id);
        return success();
    }

    @PutMapping("{id}/status/{status}")
    @ApiOperation(value = "启用-禁用规则")
    public ResponseResult setStatus(@PathVariable Long id,@PathVariable Integer status) {
        alertRuleService.setStatus(id,status);
        return success();
    }

}
